import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const mockAjax = axios.create({
  baseURL: '/mock',
  timeout: 1000,
})

mockAjax.interceptors.request.use((config) => {
  NProgress.start()
  return config
})

mockAjax.interceptors.response.use(
  (response) => {
    NProgress.done()
    return response.data
  },
  (error) => {
    console.log('响应失败')
    NProgress.done()
    return Promise.reject(new Error(error.message))
  }
)

export default mockAjax
